package com.liqi.frame.comm.base;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liqi.frame.comm.mybatisplus.Assist;

import java.util.List;

/**
 * 服务基础接口实现类
 * @author liqi on 2017/11/24.
 * liqiwork@qq.com
 */
public abstract class BaseServiceImpl<T> extends ServiceImpl<BaseMapper<T>, T> implements BaseService<T> {
    public int insertObject_common(T t) {
        return getDao().insertObject_common(t);
    }

    public int updateObject_common(T t) {
        return getDao().updateObject_common(t);
    }

    public int deleteById_common(Object id) {
        return getDao().deleteById_common(id);
    }

    public T selectById_common(Object id) {
        return (T)getDao().selectById_common(id);
    }

    public List<T> selectList_commom(Assist assist) {
        return getDao().selectList_commom(assist);
    }

    public PageInfo<T> selectList_commom(Assist assist, Integer page, Integer limit){
        if (null == assist) {
            assist = Assist.getInstance();
        }
        PageHelper.startPage(page, limit);
        List<T> list = this.selectList_commom(assist);
        PageInfo pageInfo;
        if (list!=null) {
            pageInfo = new PageInfo(list);
        } else {
            pageInfo = null;
        }
        return pageInfo;
    }

    protected abstract BaseDao getDao();
}
